apiready = function(){
seajs.use(['../../V',"../../api","../../jquery","../../app","../../service","../../pop"],function(V,$api,$,$app,service,$pop){
	var vm = {
		el: '.container',
	  	data: {
	    	wayIndex: -1,
	    	info:{
	    		title: '转账到支付宝',
	    		name: '账户名称',
	    		account: '支付宝账号',
	    		placeholder: '请输入支付宝账号'
	    	},
	    	account_name: '',    //--真实姓名
	    	account_number: '',  //--账户
	    	account_type: -1,    //--提现方式
	    	account_money: '',   //--提现金额
	    	money: 0,            //--可提现金额
	    	name: ''
	  	},
	  	methods:{
	  		init: function(){
	  			var unionid = $api.getStorage("shop_unionid"), self = this;
	  			$app.ajax(service.buyWithdraw,{
					data: {
						values: {
							unionid: unionid
						}
					}
				},function (res) {
					console.log("buy_withdraw： "+JSON.stringify(res));
					if(res.code == 0){
						self.money = res.data.can_withdraw_money;
					}
				});
	  		},
	  		//--选择支付方式
	  		withdrawSelect: function(et){
	  			if(this.money == 0){
	  				$app.toast("没有可提现金额！");
	  				return;
	  			}
	  			var index = +et.currentTarget.dataset.index;
	  			this.wayIndex = index;
	  			if(index == 0){
	  				this.info.title = '确认提现到微信钱包！';
	  				this.info.name = '微信名称';
	  				this.info.account = '微信钱包';
	  				this.info.placeholder = '请输入微信账号';
	  				this.account_type = 1;
	  			}
	  			if(index == 1){
	  				this.info.title = '转账到支付宝';
	  				this.info.name = '真实姓名';
	  				this.info.account = '支付宝账户';
	  				this.info.placeholder = '请输入支付宝账号';
	  				this.account_type = 2;
	  			}
	  			if(index == 2){
	  				//--银行卡
	  				this.openBank();
	  			}
	  		},
	  		//--打开银行卡提现
	  		openBank: function(){
	  			var money = this.money
	  			$app.openWin('buyWithdrawBank',{
	  				name: api.pageParam.prve,
	  				money: money
	  			});
	  		},
	  		//--打开支付宝或者微信
	  		openWxApliy: function(){
	  			this.$refs.withdrawPop.style.display = 'block';
	  		},
	  		closeWxApliy: function(){
	  			this.$refs.withdrawPop.style.display = 'none';
	  		},
	  		//--确认支付方式
	  		sureSelcet: function(){
	  			if(this.money == 0){
	  				$app.toast("没有可提现金额！");
	  				return;
	  			}
				if(this.wayIndex == -1){
					$app.toast("请选择提现方式！");
	  				return;
				}
	  			if(this.wayIndex == 2){
	  				//--银行卡
	  				this.openBank();
	  			}else{
	  				//--1支付宝，0微信
	  				this.openWxApliy();
	  			}
	  		},
	  		//--提交提现
	  		submitWithdraw: function(){
	  			var unionid = $api.getStorage("shop_unionid"), self = this;
	  			var values = {}
	  			this.account_money = this.money;
	  			values.unionid = unionid;
	  			values.type = this.account_type;
	  			if(this.account_type == 2){
	  				values.realname = this.$refs.accountName.value || '';
	  				values.account = this.$refs.accountNumber.value || '';
	  			}
	  			if(values.realname == '' && this.account_type == 2){
	  				$app.toast("请输入"+this.info.name+"！");
	  				return;
	  			}
	  			if(values.account == '' && this.account_type == 2){
	  				$app.toast(this.info.placeholder);
	  				return;
	  			}
	  			if(this.account_type == -1){
	  				$app.toast('请选择提现方式！');
	  				return;
	  			}
	  			$app.ajax(service.buyWithdrawApply,{
					data: {
						values: values
					}
				},function (res) {
					console.log("buy_withdraw_apply： "+JSON.stringify(res));
					if(res.code == 0){
						$app.toast("提现申请成功！");
						api.sendEvent({
							name:'withdraw_',
						});
						$api.setTimeout(function(){
							api.closeToWin({
								name: api.pageParam.prve
							});
						},300);
					}
				});
	  		}
	  	},
	  	mounted:function() {
	  		var self = this;
	  		api.addEventListener({
	  			name: 'withdrawBank_'
	  		},function(){
	  			self.wayIndex = -1;
	  			self.init();
	  		});
	  	},
	  	created: function(){
	  		this.init();
	  	}
	};
	var even = function() {}
	var newVue = new Vue(vm);
	even();
});
}
